﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Oracle.ManagedDataAccess.Client;
using Oracle.ManagedDataAccess.Types;
using System.IO;
using System.Transactions;

namespace OracleDalc
{
	public class DatabaseFilesDALC
	{
		public void Test()
		{
			string cstr = @"DATA SOURCE=DEV;PERSIST SECURITY INFO=True;USER ID=DBS$DOC;PASSWORD=DBS$DOC";
			OracleConnection conn;
			using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
			{
				conn = new OracleConnection(cstr);
				conn.Open();
				OracleCommand cmd = conn.CreateCommand();

				//OracleTransaction txn = conn.BeginTransaction();

				cmd.CommandText = "SELECT id, body FROM files where id = 5";
				OracleDataReader reader = cmd.ExecuteReader();
				//Obtain the first row of data.
				reader.Read();

				OracleBlob blob = null;
				if (!reader.IsDBNull(1))
					blob = reader.GetOracleBlobForUpdate(1);
				reader.Close();
				using (Stream sblob = blob as Stream)
				{
					sblob.Position = 0;
					//sblob.SetLength(0);
					//sblob.Position = sblob.Length;
					using (StreamWriter wr = new StreamWriter(sblob))
					{
						wr.WriteLine("coded test string7");
					}
				}
				//blob.Flush();
				//txn.Commit();
				scope.Complete();
			}
			conn.Dispose();
		}
	}
}
